package com.lkd.handler;

import com.lkd.business.MsgHandler;
import com.lkd.config.TopicConfig;
import com.lkd.contract.VmStatusContract;
import com.lkd.emq.Topic;
import com.lkd.service.TaskService;
import com.lkd.utils.JsonUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.io.IOException;

@Component
@Topic(TopicConfig.VMS_STATUS_TOPIC)
public class TaskAutoRepairHandler implements MsgHandler {

    @Autowired
    private TaskService taskService;

    @Override
    public void process(String jsonMsg) throws IOException {

        // 解析数据
        VmStatusContract vmStatusContract = JsonUtil.getByJson(jsonMsg, VmStatusContract.class);

        // 检查设备状态,自动创建维修工单
        taskService.autoCreateRepairTask(vmStatusContract);

    }
}
